﻿#pragma once

#include "Render/Texture.h"

class FrameBuffer
{
public:
  FrameBuffer(int32_t width, int32_t height, bool useDepthAttachment, int32_t colorAttachmentCount);
  ~FrameBuffer();

  int32_t GetWidth() const { return m_width; }
  int32_t GetHeight() const { return m_height; }
  bool DismatchSize(int32_t width, int32_t height) const { return m_width != width || m_height != height; }
  bool IsValid() const { return m_id != 0; }
  size_t GetColorAttachmentCount() const { return m_attachments.size(); }

  Ref<Texture> GetColorAttachment(int32_t index) const { assert(index < m_attachments.size()); return m_attachments[index]; }
  Ref<Texture> GetDepthAttachment() const { return m_depthAttachment; }

  void ClearColorAttachment(int32_t index, const glm::vec4 &value);

  void Bind(bool forDrawing = true) const;
  void Draw() const;
  void Unbind() const;

  FrameBuffer(const FrameBuffer &) = delete;
  FrameBuffer(FrameBuffer &) = delete;
  FrameBuffer(FrameBuffer &&) noexcept = delete;
  FrameBuffer &operator=(FrameBuffer &) = delete;
  FrameBuffer &operator=(FrameBuffer &&) noexcept = delete;

private:
  uint32_t m_id = 0;

  int32_t m_width = 0;
  int32_t m_height = 0;
  
  std::vector<Ref<Texture>> m_attachments;
  std::vector<uint32_t> m_attachmentNames;
  Ref<Texture> m_depthAttachment{nullptr};
};